package ar.edu.unq.leezsi.html.javascript;

import ar.edu.unq.leezsi.html.OpenCloseComponent;

public class JavaScriptReference extends OpenCloseComponent<String> {
	private final String resource;
	private final Class<?> reference;

	public JavaScriptReference(Class<?> reference, String resource) {
		this.reference = reference;
		this.resource = resource;

	}

	protected Class<?> getReference() {
		return this.reference;
	}

	protected String getResource() {
		return this.resource;
	}

	@Override
	protected void onBeforeRenderer() {
		this.setAttribute("type", "text/javascript");
		this.setAttribute("src", this.getContext().getContextURI()
				+ "/resource/" + this.getReference().getCanonicalName() + "/"
				+ this.getResource());
	}

	@Override
	protected String tag() {
		return "script";
	}

}
